package com.achievement.controller;

import com.achievement.domain.dto.ArtProductDTO;
import com.achievement.domain.param.ArtProductParam;
import com.achievement.domain.vo.ArtProductVO;
import com.achievement.service.IArtProductService;
import com.common.annotation.Anonymous;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * 科研成果-艺术作品Controller
 *
 * @author ruoyi
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/achievement/artProduct")
@Api(tags = "成果管理模块-科研成果-艺术作品")
public class ArtProductController extends BaseController {
    @Autowired
    private IArtProductService artProductService;

    /**
     * 查询科研成果-艺术作品列表
     */
    @PreAuthorize("@ss.hasPermi('achievement:artProduct:list')")
    @GetMapping("/list")
    @ApiOperation(value = "分页获取艺术作品列表", notes = "分页获取艺术作品列表")
    public TableDataInfo list(ArtProductParam param) {
        startPage();
        List<ArtProductVO> list = artProductService.selectArtProductList(param);
        return getDataTable(list);
    }

    /**
     * 左上方统计 通过，退回，待审核
     * @param param 检索参数
     * @return AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('achievement:artProduct:list')")
    @ApiOperation(value = "左上方统计 通过，退回，待审核",notes = "左上方统计 通过，退回，待审核")
    @GetMapping(value = "/list-statistics")
    public AjaxResult listStatistics(ArtProductParam param)
    {
        List<HashMap<String, Integer>> list =artProductService.listStatistics(param);

        return success(list);
    }

    /**
     * 导出科研成果-艺术作品列表
     */
    @PreAuthorize("@ss.hasPermi('achievement:artProduct:export')")
    @Log(title = "科研成果-艺术作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "艺术作品成果导出", notes = "艺术作品成果导出")
    public void export(HttpServletResponse response,@RequestBody ArtProductParam param) {
        List<ArtProductVO> list = artProductService.getListByConditions(param);
        List<String> selectedColumns = param.getExcelColumn();
        ExcelUtil<ArtProductVO> util = new ExcelUtil<>(ArtProductVO.class);
        util.showColumn(selectedColumns.toArray(new String[0]));
        util.exportExcelByOrder(response, list, "科研成果-艺术作品数据",selectedColumns.toArray(new String[0]));
    }

    /**
     * 获取科研成果-艺术作品详细信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:artProduct:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取艺术作品详细信息", notes = "获取艺术作品详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(artProductService.selectArtProductByID(id));
    }

    /**
     * 新增科研成果-艺术作品
     */
    @PreAuthorize("@ss.hasPermi('achievement:artProduct:add')")
    @Log(title = "科研成果-艺术作品", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增艺术作品", notes = "新增艺术作品")
    public AjaxResult add(@RequestBody ArtProductDTO dto) {
        return artProductService.insertArtProduct(dto);
    }

    /**
     * 修改科研成果-艺术作品
     */
    @PreAuthorize("@ss.hasPermi('achievement:artProduct:edit')")
    @Log(title = "科研成果-艺术作品", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改艺术作品", notes = "修改艺术作品")
    public AjaxResult edit(@RequestBody ArtProductDTO dto) {
        return artProductService.updateArtProduct(dto);
    }

    /**
     * 删除科研成果-艺术作品
     */
    @PreAuthorize("@ss.hasPermi('achievement:artProduct:remove')")
    @Log(title = "科研成果-艺术作品", businessType = BusinessType.DELETE)
    @DeleteMapping("/del/{ids}")
    @ApiOperation(value = "删除艺术作品", notes = "删除艺术作品")
    public AjaxResult remove(@PathVariable List<String> ids) {
        return toAjax(artProductService.deleteArtProductByIDs(ids));
    }
}
